define("pages/jls_sj/hsdjmain", [
    "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
    "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
    "../../plugins/artTemplate/artTemplate",
    "../../common/tools",
    "../../common/kss",
    "../../common/componts",
    "../../pages/jls_sj/hsdjform",
],

function(require) {
    var comonts=require("../../common/componts");
    var kss=require("../../common/kss");
    var jbxxid="hsdjId";
    var hsdj=require("../../pages/jls_sj/hsdjform");
    // var hsqddjdiog = require("");
    var selectid;
    var id;

    var Select = function(){
        comonts.initSelectPage(undefined);
        comonts.initSelect(undefined,undefined,undefined);
    }

    var tableInit=function(){
        comonts.initTable(jbxxid,{
            url:"/jls_jbxx/jbxxList",
            title:'',
            fit:true,
            tools:'#xscxId',
            columns :  [
                {
                    field: 'oid',
                    title: '序号',
                    formatter: function(value, rowData, rowIndex){
                        return '<input type="radio" name="ryRadio" id="ryRadio' + rowIndex + '" value="' + rowData.oid + '" />';
                    }},
                {field : 'clgw',title : '拘室号',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(row.xm==null?"":row.xm)+'>'+(row.xm==null?"":row.xm)+'</span>'}},
                {field : 'clr',title : '姓名',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(row.bm==null?"":row.bm)+'>'+(row.bm==null?"":row.bm)+'</span>'}},
                {field : 'clrqString',title : '离所日期',width : 200,sortable:'true',formatter: function(value,row,index){return '<span title='+value+'>'+value+'</span>'}},
                {field : 'clqkString',title : '准假期限',width : 80,sortable:'true',formatter: function(value,row,index){return '<span title='+value+'>'+value+'</span>'}},
                {field : 'clrqString',title : '请假结束日期',width : 200,sortable:'true',formatter: function(value,row,index){return '<span title='+value+'>'+value+'</span>'}},
                {field:'operate',title:'详细信息',align:'center',width : 60,/*width:$(this).width()*0.15,*/
                    formatter:function(value, row, index){
                        var str = '<a href="#" data-target="#ckPhoto" value="'+index+'" name="opera" data-toggle="modal" class="easyui-linkbutton"><img src="../../img/xq.png"></a>';
                        return str;
                        //return  '<button id="sh_add" onclick="add"  > 不通过</button>'
                    }
                }
            ] ,
            //基本信息双击事件
            onDblClickRow:function(rowIndex, rowData){
                $("input[name='ryRadio']")[rowIndex].checked = true;
                $("#"+jbxxid).datagrid("selectRow", rowIndex);
                selectid=rowData.id;
            },

            // onLoadSuccess:function(data){
            // 	if(data.total>0){
            // 		$('#'+jbxxid).datagrid("selectRow", 0);
            // 		$("input[name='ryRadio']")[0].checked = true;
            // 	}
            //
            // 	$("a[name='opera']").on('click',function(){
            // 			var jbxx = $('#'+jbxxid).datagrid("getSelected");
            // 			kss.initRyJbxx(jbxx);
            // 	});
            // 	$('.datagrid-pager').find('.pagination-info').css('margin-right','25px');
            //
            // },

            onLoadSuccess:function(data){
                if(data.total>0){
                    $('#'+jbxxid).datagrid("selectRow", 0);
                    $("input[name='ryRadio']")[0].checked = true;
                }
                $("a[name='opera']").each(function(){
                    $(this).on('click',function () {
                        var index = $(this).attr('value');
                        var jbxx = data.rows[index];
                        kss.initJbxxxx(jbxx.gcbh,jbxx.rybh,jbxx.xm+"--详细信息");
                    });
                });
            },

            //单击行选中取消事件
            onClickRow:function(rowIndex, rowData){
                if(selectid!=rowData.id){
                    $("input[name='ryRadio']")[rowIndex].checked = true;
                    selectid=rowData.id;
                }else{
                    $("#"+jbxxid).datagrid("unselectRow",rowIndex);
                    $("input[name='ryRadio']")[rowIndex].checked = false;
                    $('#'+jbxxid).datagrid('clearSelections');
                    selectid="";
                }
            },
            onSelect:function(rowIndex, rowData){
            },
            rightmenu:function(){
                //kss.initJbxxRightMenu(jbxxrightmenuid);
            },
        });
        //页面高度自适应
        $('#'+jbxxid).datagrid('resize',{
            height:($(window).height()-160),
        });
    }

    var findJbxx=function(){
        var xm = $("#tz_xm").text('getValue');
        $('#'+jbxxid).datagrid('clearSelections');
        $('#'+jbxxid).datagrid('load',{
            'state':'R8',
        });
    }

    var hsdjfrom = function(){
        //获得当前时间
        var d = new Date();
        var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
        hsdj.show(jbxxid,{},refreshTable);
    }

    var refreshTable=function(data){
        $('#'+jbxxId).datagrid('reload',{rybh:$('#'+jbxxId).datagrid('getSelected').rybh,"taskDefinitionKey":"kss_rsdj_zbsy","processDefinitionKey":"kss_rsdj"});
    }

    var bindAction=function(){

        $("#wsbd_query").on("click",function(){
            findJbxx();
        });

        $("#hsdj_query").on("click",function () {
            var jbxx=$("#"+jbxxid).datagrid('getSelected');
            if(jbxx){
                console.log(hsdj);
                hsdjfrom();
            }else{
                $.messager.alert("提示","请选择要办理的人员!","info");
            }
        });

        $(window).keydown(function(event) {
            if (event.keyCode == 13) {
                findJbxx();
            }
        });

    }


    // var tsDc = function(){
    //     var jbxx = $("#"+jbxxid).datagrid("getChecked");
    //     console.log(jbxx);
    //     if(jbxx.length!=0){
    //         hsqddjdiog.show(jbxx);
    //     }else{
    //         $.messager.alert("提示","正在加载","info");
    //     }
    // }
    //
    // $("#dcExc").on("click",function(){
    //     tsDc();
    // });
    //
    // $("#dy").click(function(){
    //     $('#dywin').window('open');
    // });

    var initView=function(){
        tableInit();
        bindAction();
        Select();
    }
    initView();
});
